package com.yuma.string;

public class StringDemo {
    public static void main(String[] args) {
        String s1 = "abc";
        String s2 = new String("abc");   // final byte[]
        String s3 = "a" + "b" + "c";   // 优化 常量池
        String s5 = "bc";
        String s4 = "a" + "bc";   // 优化 常量池
        String s6 = "a" + s5;   // 有变量的情况  new StringBuilder("a").append(s5)
        String a = "a";
        String s7 = a + "bc";   // 有变量的情况  new StringBuilder(a).append("bc")

        System.out.println(s1 == s2);  // false
        System.out.println(s1 == s3);  // true
        System.out.println(s1 == s4);  // true
        System.out.println(s1 == s6);  // false
        System.out.println(s1 == s7);  // false

    }
}
